package com.zp.base.dubbo;

import cn.hutool.core.collection.CollectionUtil;
import com.zp.base.api.RemoteAdministrationDictService;
import com.zp.base.api.vo.AdministrationDictVo;
import com.zp.base.entity.administrationDict.bo.AdministrationDictBo;
import com.zp.base.service.administrationDict.IAdministrationDictService;
import com.zp.common.core.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Service
@DubboService
public class RemoteAdministrationDictServiceImpl implements RemoteAdministrationDictService {

    private final IAdministrationDictService administrationDictService;


    @Override
    public List<AdministrationDictVo> queryList (String orgId) {
        AdministrationDictBo bo = new AdministrationDictBo();
        bo.setOrgId(orgId);
        return administrationDictService.queryList(bo);
    }

    @Override
    public String getAdministrationLabel (String orgId, String channel) {
        // 获取途径字典
        List<AdministrationDictVo> administrationDictVos = queryList(orgId);
        List<AdministrationDictVo> collect = administrationDictVos.stream().filter(administrationDict ->
                StringUtils.equals(administrationDict.getValue(), channel)).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(collect)) {
            return collect.get(0).getLabel();
        }
        return "";
    }
}
